<?php
/**
 *       _____
 *      /  \  \      _       _    _____________   ___     ___ '  TM
 *     / /\ \  \    | |\    | |\ /_____   _____\ | - |   | - |
 *    / /  \ \  \   | | |   | | ||____/| |\____| | - |___| - |
 *   / /   /\ \  \  | | |   | | |    | | | |     | -  ___  - |
 *  / /   /  \ \  \ | |_|___| | |    | |_| |     | - |   | - |
 * / /___/    \ \__\|________ |/     |/___\|     |___|   |___|
 *________________________________________________________________________

 * Security Scanner will scan directories to find virus or changed file.
 *
 * PHP version 5
 *
 * LICENSE: GNU General Public License v3
 *
 * @category
 * @package
 * @author     Charly Poly <CharlyPoly@gmail.com>
 * @copyright  2009 Authentic Development Group
 * @license    GNU General Public License v3
 * @since      File available since Release 0.1.0
 */

class scanner {
    private $result           = array();
    private static $hashesDir = "Scanner_h";

    const DIFFONLY            = "DIFFMODE";
    const DIFFANDSCAN         = "DIFF&SCAN";
    const SCANONLY            = "SCAN";

    private $mode             = self::DIFFANDSCAN;


    public function __construct($mode, $toScan=NULL) {
        // INIT

        if ($mode == self::DIFFANDSCAN || $mode == self::DIFFONLY || $mode == self::SCANONLY) {
            $this->mode = $mode;
        } else {
            //Error
        }

        $this->result['warning'] = array();
        $this->result['warning']['NotAnImage'] = array();
        $this->result['dangerous'] = array();
        $this->result['diff'] = array();

        // START
        if (is_null($toScan)) {
            $this->ScanAll();
        } elseif (is_file($toScan)) {
            $this->ScanFile($toScan);
        } elseif (is_dir($toScan)) {
            $this->ScanDir($toScan);
        } else {
            //Error
        }

        return $this->result;
    }

    private function ScanFile ($file) {
        switch ($this->mode) {
            case self::SCANONLY:
                return $this->Scan($file);
                break;
            case self::DIFFANDSCAN:
                $s = $this->Scan($file);
                $d = $this->Diff($file);
                return ($s === TRUE && $d === TRUE);
                break;
            case self::DIFFONLY:
                return $this->Diff($file);
                break;
            default:
                //Error
                break;
        }
        
    }

    private function ScanDir($dir) {

    }

    private function ScanAll() {

    }

    private function Diff($f) {

    }

    private function Scan($f) {
        if (preg_match('/^([A-Za-z0-9])+\.(jpg|bmp|gif|png)/i',$f)) {
            $available = getimagesize($f);
            if (!available) {
                $this->result['warning']['NotAnImage'][] = $f;
                return FALSE;
            }
            return TRUE;
        }
        //Autres Tests...(FileInfo)
    }

    private function createHashFile($files) {

    }

}
?>
